

'''
 * NodeTable wrapper to handle inline node ids.
 * If a node can be made inline, then the underlying table never sees it.
 * If an inline Nodeid is seen, it is decoded and returned without
 * the underlying table being called.
'''

from NodeTableWrapper import NodeTableWrapper
from db import NodeId

class NodeTableInline(NodeTableWrapper):
    # Stack order: Inline > Cache > Actual

    def NodeTableInline(self, nodeTable):
        super().__init__(nodeTable)
    
    #private NodeTableInline(NodeTable nodeTable):
        #super()(nodeTable)
    #

    
    # param NodeTable
    # result NodeTable
    def create(self, nodeTable):
        return NodeTableInline(nodeTable)
    

    # param Node
    # result NodeId
    def getAllocateNodeId(self, node):
        # NodeId 
        nid = NodeId.inline(node)
        if (nid is not None):
            return nid
        return super().getAllocateNodeId(node)
    

    # param Node
    # result NodeId
    def getNodeIdForNode(self, node):
        #NodeId 
        nid = NodeId.inline(node)
        if (nid is not None):
            return nid
        return super().getNodeIdForNode(node)
    

    # param 
    # result Node
    def getNodeForNodeId(self, id):
        #Node 
        n = NodeId.extract(id)
        if (n is not None):
            return n
        return super().getNodeForNodeId(id)
    

    # param
    # result String
    def toString(self):
        return "Inline(" + self.nodeTable.toString() + ")"